<?php
// +----------------------------------------------------------------------
// | zhanshop-docker-server / http.php    [ 2022/5/1 12:18 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011~2022 zhangqiquan All rights reserved.
// +----------------------------------------------------------------------
// | Author: Administrator <768617998@qq.com>
// +----------------------------------------------------------------------

use app\api\admin\WebsocketEvent;
use zhanshop\App;
use zhanshop\server\Event;
use zhanshop\console\command\Server;
use zhanshop\server\event\McpEvent;

return [
    'servers' => [
        [
            'name'      => 'admin',
            'mode'      => (int)App::env()->get("SERV_MODE", "2"),
            'host'      => App::env()->get("SERV_HOST", "0.0.0.0"),
            'port'      => (int)App::env()->get("ADMIN_PORT", "7201"),
            'sock_type' => (int)App::env()->get("SOCK_TCP_TYPE", "1"),
            'serv_type' => Server::WEBSOCKET,
            'callbacks' => [
                Event::ON_INITIAL => function () {
                    \zhanshop\util\ShareData::make();
                    \zhanshop\RamCache::create();
                },
                Event::ON_WORKER_START => [WebsocketEvent::class, 'onWorkerStart'],
                Event::ON_REQUEST => [WebsocketEvent::class, 'onRequest'],
                Event::ON_OPEN => [WebsocketEvent::class, 'onOpen'],
                Event::ON_MESSAGE => [WebsocketEvent::class, 'onMessage'],
                Event::ON_CLOSE => [WebsocketEvent::class, 'onClose'],
            ]
        ],
        [
            'name'      => 'mcp',
            'mode'      => (int)App::env()->get("SERV_MODE", "1"),
            'host'      => App::env()->get("SERV_HOST", "0.0.0.0"),
            'port'      => (int)App::env()->get("MCP_PORT", "3000"),
            'sock_type' => (int)App::env()->get("SOCK_TCP_TYPE", "1"),
            'serv_type' => Server::HTTP,
            'callbacks' => [
                Event::ON_REQUEST => [McpEvent::class, 'onRequest'],
            ]
        ],
    ],
    'settings' => [
        'worker_num' => 2,
        'reactor_num' => 1,
        'task_worker_num' => 1,
        'enable_static_handler' => boolval(App::env()->get("STATIC_ACCESS", "1")),
        'http_autoindex' => true,
        'http_index_files' => ['index.html'],
        'document_root' => App::rootPath().DIRECTORY_SEPARATOR.'public',
        'send_yield' => true,
        // 一个TCP连接的最少需要占用 224 字节
        'max_connection' => 200000,
        // 底层默认分配2M(C)虚拟内存+8K(PHP)内存
        'max_coroutine' => 100000, // 一个协程初始化的时候默认约占用8K物理内存
        'buffer_output_size' => 10 * 1024 * 1024,
        'package_max_length' => 10 * 1024 * 1024,
        'open_tcp_keepalive' => true,
        'tcp_keepidle' => 60,
        'tcp_keepinterval' => 60,
        'tcp_keepcount' => 1,
    ],
    'crontab' => [
        \zhanshop\console\crontab\WatchLogCronTab::class, // 定期清理日记
        \app\crontab\NginxLogCrontab::class, // nginx访问日志的每日清理
        \app\crontab\NginxStatusCrontab::class, // nginx连接数监测
        \app\crontab\CloudappStatCrontab::class, // 监测每个容器的cpu内存和网络消耗情况
        \app\crontab\CloudLogStatCrontab::class, // 统计上一天nginx请求数量,IP排行榜信息
        \app\crontab\CloudCrontab::class, // 基于可配置的定时任务
    ],
    'process' => [
        //\app\process\Logstash::class
    ],
];
